package cn.okcode.slowjson.ast;

import cn.okcode.slowjson.parser.Serializer;
import cn.okcode.slowjson.parser.Visitor;

import java.util.Objects;

/**
 * @author pyk13
 */
public class PropertyNode extends AbstractNode<String> {
    private final String value;
    private final boolean propertyNameStyle;

    public PropertyNode(String value, boolean propertyNameStyle) {
        Objects.requireNonNull(value);
        this.value = value;
        this.propertyNameStyle = propertyNameStyle;
    }

    public PropertyNode(String value) {
        Objects.requireNonNull(value);
        this.value = value;
        this.propertyNameStyle = true;
    }

    @Override
    public String getValue() {
        return value;
    }

    @Override
    public String stringValue() {
        return propertyNameStyle ? ("\"" + Serializer.serializeString(value) + "\"") : value;
    }

    @Override
    public void accept(Visitor visitor) {
        visitor.visit(this);
    }

    @Override
    public int hashCode() {
        return value.hashCode();
    }

    @Override
    public boolean equals(Object obj) {
        return super.equals(obj);
    }
}
